<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同信息"><!--,status>10-->
              <j-search-select-tag :async="true" placeholder="请选择合同信息" v-model="queryParam.leaseContractId"
                                   dict="zcgl_lease_contract_info,contract_num,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="资产信息"><!--,status>1-->
              <j-search-select-tag :async="true" placeholder="请选择资产信息" v-model="queryParam.assetId"
                                   dict="zcgl_asset_info,asset_name,id"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户信息">
                <j-search-select-tag :async="true" placeholder="请选择客户信息" v-model="queryParam.customerId"
                                     dict="zcgl_customer_info,name,id"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="款项说明">
                <j-dict-select-tag placeholder="款项说明" v-model="queryParam.paymentInstructions"
                                   dictCode="payment_instructions"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button v-has="'collectionInformation:export'" type="primary" icon="download"
                @click="handleExportXls('应收已收未收')">导出
      </a-button>
      <!--      <a-upload v-has="'collectionInformation:import'" name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"-->
      <!--                @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import">导入</a-button>-->
      <!--      </a-upload>-->
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importXlsDictUrl"-->
      <!--                @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import">导入a</a-button>-->
      <!--      </a-upload>-->
      <!--      <a-button v-has="'collectionInformation:temp'" type="primary" icon="download" @click="handleExportXlsTemplate('应收已收未收模板')">模板下载</a-button>-->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
      <!--        <a-menu slot="overlay">-->
      <!--          <a-menu-item key="1" @click="batchDel">-->
      <!--            <a-icon type="delete"/>-->
      <!--            删除-->
      <!--          </a-menu-item>-->
      <!--        </a-menu>-->
      <!--        <a-button style="margin-left: 8px"> 批量操作-->
      <!--          <a-icon type="down"/>-->
      <!--        </a-button>-->
      <!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{-->
      <!--        selectedRowKeys.length }}</a>项-->
      <!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--      </div>-->

      <a-table
        ref="table"
        size="middle"
        bordered
        :scroll="{ x: 3000, y: screenHeight }"
        rowKey="id"
        class="j-table-force-wrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <span slot="serial" slot-scope="text,record,index">{{ index + 1 }}</span>
        <template slot="footer" slot-scope="currentPageData">
          <a-table
            bordered
            class="footerTable"
            size="small"
            :columns="footColumns"
            :dataSource="footerData"
            :scroll="{ x: 3000, y: screenHeight }"
            :pagination="false"
            :showHeader="false">
            <span slot="serial">合计</span>
          </a-table>
        </template>
      </a-table>
    </div>

    <assetInfo-modal ref="modalForm" @ok="modalFormOk"></assetInfo-modal>
    <assetInfoDisposal-modal ref="modalDisposalForm" @ok="modalDisposalOk"></assetInfoDisposal-modal>
  </a-card>
</template>

<script>

import { getAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import AssetInfoModal from './modules/AssetInfoModal'
import AssetInfoDisposalModal from './modules/AssetInfoDisposalModal'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import JInput from '@/components/jeecg/JInput'
import '@/assets/less/TableExpand.less'
import JSearchSelectTag from '@comp/dict/JSearchSelectTag'

export default {
  name: 'collectionInformationList',
  mixins: [JeecgListMixin],
  components: {
    JInput,
    JDictSelectTag,
    JSearchSelectTag,
    AssetInfoDisposalModal,
    AssetInfoModal
  },
  data () {
    return {
      description: '应收已收未收',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'rowIndex',
          key: 'rowIndex',
          width: 80,
          align: 'center',
          fixed: 'left',
          customRender: (text, record, index) =>
            `${(this.ipagination.current - 1) * this.ipagination.pageSize + index + 1}`
        },
        {
          title: '合同编号',
          align: 'center',
          // fixed:"left",
          // width: 200,
          // ellipsis: true,
          dataIndex: 'leaseContractId_dictText'
        },
        {
          title: '资产名称',
          align: 'center',
          dataIndex: 'assetId_dictText'
        },
        {
          title: '资产明细',
          align: 'center',
          dataIndex: 'assetSubIds_dictText'
        },
        {
          title: '客户名称',
          align: 'center',
          dataIndex: 'customerId_dictText'
        },
        {
          title: '总金额',
          align: 'center',
          dataIndex: 'amountMoney',
          customRender: function (text) {
            if (!text) {
              text = 0
            }
            return text.toLocaleString('zh-Hans-CN', { style: 'currency', currency: 'CNY' })
          }
        },
        {
          title: '款项说明',
          align: 'center',
          // fixed:"left",
          // width: 200,
          dataIndex: 'paymentInstructions_dictText'
        },
        {
          title: '应收金额',
          align: 'center',
          dataIndex: 'receivableMoney',
          customRender: function (text) {
            if (!text) {
              text = 0
            }
            return text.toLocaleString('zh-Hans-CN', { style: 'currency', currency: 'CNY' })
          }
        },
        {
          title: '已收金额',
          align: 'center',
          dataIndex: 'receivedMoney',
          customRender: function (text) {
            if (!text) {
              text = 0
            }
            return text.toLocaleString('zh-Hans-CN', { style: 'currency', currency: 'CNY' })
          }
        },
        {
          title: '未收金额',
          align: 'center',
          dataIndex: 'uncollectedMoney',
          customRender: function (text) {
            if (!text) {
              text = 0
            }
            return text.toLocaleString('zh-Hans-CN', { style: 'currency', currency: 'CNY' })
          }
          // customRender: function (t, r, index) {
          //   if (r.status == 40) {
          //     return t + '（' + r.assetDisposal_dictText + '）'
          //   }
          //   return t
          // }
        },
        {
          title: '预付款',
          align: 'center',
          // width: 200,
          dataIndex: 'balance',
          customRender: function (text) {
            if (!text) {
              text = 0
            }
            return text.toLocaleString('zh-Hans-CN', { style: 'currency', currency: 'CNY' })
          }
        },
        {
          title: '收费率（%）',
          align: 'center',
          dataIndex: 'rateCharge',
          customRender: function (text) {
            if (!text) {
              text = 0
            }
            return text.toFixed(2) + '%'
          }
        }
      ],
      tableData:[],
      footColumns: [],
      footerData: [{
        key: '1',
        leaseContractId_dictText: '',
        assetId_dictText: '',
        assetSubIds_dictText: '',
        customerId_dictText: '',
        amountMoney: '',//
        paymentInstructions_dictText: '',
        receivableMoney: '',//
        receivedMoney: '',//
        uncollectedMoney: '',//
        balance: '',//
        rateCharge: ''
      }],
      url: {
        list: '/zcgl/statisticalReport/collectionInformation',
        exportXlsUrl: '/zcgl/statisticalReport/collectionInformation/exportXls',
        importXlsDictUrl: '/zcgl/statisticalReport/dict/importExcel',
        importExcelUrl: 'zcgl/statisticalReport/collectionInformation/importExcel',
        exportXlsTemplate: 'zcgl/statisticalReport/collectionInformation/exportXlsTemplate'
      },
      dictOptions: {}
    }
  },
  created () {
    this.footColumns.push({
      title: '序号',
      dataIndex: 'rowIndex',
      key: 'rowIndex',
      width: 80,
      align: 'center',
      fixed: 'left',
      customRender: (text, record, index) =>
        '合计'
    })
    this.columns.forEach(value => {
      if (value.title !== '序号') {
        this.footColumns.push(value)
      }
    })
  },
  mounted () {
    const dom = this.$refs.table.$el.querySelectorAll('.ant-table-body')[0]
    dom.addEventListener('scroll', () => {
      this.$refs.table.$el.querySelectorAll('.ant-table-body')[1].scrollLeft = dom.scrollLeft
    }, true)
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    importXlsDictUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importXlsDictUrl}`
    }
  },
  methods: {
    loadData (arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams()//查询条件
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        console.log(this.url.list + ':')
        console.log(res)
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total

          let amountMoney = 0
          let receivableMoney = 0
          let receivedMoney = 0
          let uncollectedMoney = 0
          let balance = 0
          res.result.records.forEach(value => {
            amountMoney += value.amountMoney
            receivableMoney += value.receivableMoney
            receivedMoney += value.receivedMoney
            uncollectedMoney += value.uncollectedMoney
            balance += value.balance
          })
          this.footerData[0].amountMoney = amountMoney
          this.footerData[0].receivableMoney = receivableMoney
          this.footerData[0].receivedMoney = receivedMoney
          this.footerData[0].uncollectedMoney = uncollectedMoney
          this.footerData[0].balance = balance
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    initDictConfig () {
      this.addColumns()
    },
    modalDisposalOk () {
      this.loadData()
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
<style>
.ant-table-footer {
  padding: 0;
}

.footerTable .ant-table-body {
  margin: 0px !important;
}

.footerTable .ant-table-thead {
  display: none;
}

.ant-table-footer .ant-table-body {
  overflow-x: hidden !important;
}

.footerTable .ant-table-small .ant-table-bordered {
  border: 0px;
}

.footerTable .ant-table-small .ant-table-bordered .ant-table-footer {
  border: 0px;
}
</style>